package playlist;

import java.io.IOException;
import java.util.Enumeration;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

public class Playlist {

	protected String type;
	protected String dir;
	protected int size;
	
	public Playlist(String type, String dir) {
		super();
		this.type = type;
		this.dir = dir;
		sandboxCalulateSize();
	}
	
	private void sandboxCalulateSize() {
		try {
			calculateSize();
		} catch (IOException e) {
			Crawler.alert(e);
		}
	}

	protected void calculateSize() throws IOException {
		FileConnection connection = (FileConnection) Connector.open(dir);
		Enumeration files = connection.list("*.mp3", true);
		int index = 0;

		while (files.hasMoreElements()) {
			String mp3 = (String) files.nextElement();
			index++;
		}
		connection.close();
		size = index;
	}

	public String getType() {
		return type;
	}

	public String getDir() {
		return dir;
	}

	public int getSize() {
		return size;
	}
}
